home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue15 / source / example-2a.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-14  |  4.0 KB  |  134 lines

  1. #include <stdio.h>
  2. #include <ri.h>
  3.  
  4. /*
  5.  * BMRT Introduction - Michael J. Hammel
  6.  * Example 2a - a sphere over a plane
  7.  */
  8. main()
  9. {
  10.    /* The angle of the field of view of this image */
  11.    RtFloat fov = 35.0;
  12.  
  13.    /* The color we'll use for the sphere */
  14.    RtColor blue = { 0.2,0.3,0.9 };
  15.  
  16.    /* The color we'll use for the plane under the sphere */
  17.    RtColor gray = { 0.9, 0.9, 0.9 };
  18.  
  19.    /* The intensity level of the distant light */
  20.    RtFloat intensity = 1.0;
  21.  
  22.    /*
  23.     * Coordinates for the distant light.
  24.     */
  25.    RtPoint from = {0.0, 10.5, -6.0};
  26.    RtPoint to = {0.0, 0.0, 0.0};
  27.  
  28.    /* The coordinates of the corners of our plane */
  29.    RtPoint points[4] = { 
  30.          -3.0, 0.0, 0.0,
  31.           3.0, 0.0, 0.0,  
  32.           3.0, 3.0, 0.0,
  33.          -3.0, 3.0, 0.0
  34.          };
  35.  
  36.    /*
  37.     * RI_NULL means send RIB output to standard out; this could be 
  38.     * changed to a filename to force the RIB to a specific file.  You can
  39.     * also specify the name of the one of the BMRT renderers which will
  40.     * cause the output to be piped directly to that renderer.
  41.     */
  42.    RiBegin(RI_NULL);
  43.  
  44.       /*
  45.        * The filename of the rendered image is specfified in the RiDisplay
  46.        * command.  This is not where the RIB output goes, this is where
  47.        * the output from the renderer goes.
  48.        */
  49.       RiDisplay ("example-2a.tif", RI_FILE, RI_RGB, RI_NULL);
  50.  
  51.       /*
  52.        * Image size - the "1" is the ratio of width to height for pixels.
  53.        * Unless you're using non-square pixels this should always be 1.
  54.        */
  55.       RiFormat (480, 360, 1);
  56.  
  57.       /*
  58.        * Set the samples per pixel to be 1 in each direction.
  59.        */
  60.       RiPixelSamples ( 1, 1 );
  61.  
  62.       /*
  63.        * Perspective views give a more realistic sense of depth to
  64.        * the image.  
  65.        */
  66.       RiProjection ( RI_PERSPECTIVE, RI_FOV, (RtPointer)&fov, RI_NULL );
  67.  
  68.       /*
  69.        * Set our initial position for World objects.  Basically this 
  70.          * is just setting our initial camera position to 8 units in 
  71.          * the positive Z direction.  Any changes we would make to the
  72.          * cameras postion would be relative to this.
  73.        */
  74.       RiTranslate (0, 0, 8);
  75.  
  76.       /*
  77.        * Now we start to define the objects in our scene.
  78.          * All our rendering options are frozen inside the World commands.
  79.        */
  80.       RiWorldBegin();
  81.  
  82.          /*
  83.           * Set up a distant light source.  Distant lights have parallel
  84.              * rays which follow a line parallel to the line defined by
  85.              * "from" and "to" below.
  86.           */
  87.          RiLightSource(RI_DISTANTLIGHT, RI_INTENSITY, &intensity, 
  88.                RI_FROM, (RtPointer)from, RI_TO, (RtPointer)to, RI_NULL);
  89.  
  90.          /*
  91.           * Each object has its own set of attributes.  Putting them
  92.           * inside the Attribute commands prevents us from accidently
  93.           * forgetting to reset the attributes, such as a colors,
  94.           * for a later object.
  95.           */
  96.          RiAttributeBegin();
  97.  
  98.             /*
  99.              * We need to set the surface texture of the sphere first.  Here
  100.              * we use a simple matte surface shader which is provided
  101.              * in the BMRT distribution.  The surface will have a blue
  102.                  * color.
  103.              */
  104.             RiColor(blue);
  105.             RiSurface("matte", RI_NULL);
  106.  
  107.             /*
  108.              * Next we define our sphere.  We'll move it up a little from
  109.                  * the XZ plane.
  110.              */
  111.             RiTranslate ( 0, 0.75, 0.0 );
  112.             RiSphere(0.8,-0.8, 0.8, 360.0, RI_NULL);
  113.  
  114.          RiAttributeEnd();
  115.  
  116.          /*
  117.           * Now a shiny, metal plane below the sphere.
  118.           */
  119.          RiAttributeBegin();
  120.             RiColor(gray);
  121.             RiSurface("shinymetal", RI_NULL);
  122.             RiTranslate ( 0, -1.0, 2.0 );
  123.             RiRotate ( 80, 1, 0, 0 );
  124.             RiPolygon(4, RI_P, (RtPointer)points, RI_NULL);
  125.          RiAttributeEnd();
  126.  
  127.         /*
  128.          * Don't forget:  RiWorldEnd() causes the current scene to be 
  129.          * written to the output file (or standard out if no file is
  130.          * defined).
  131.          */
  132.       RiWorldEnd();
  133. }
  134.